//
//  CHNoCheckCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/5.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHNoCheckCell.h"
@interface CHNoCheckCell()

@property (nonatomic ,strong) UIImageView *photoImgView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *addressLabel;
@property (nonatomic ,strong) UILabel *timeLabel;
@property (nonatomic ,strong) UIImageView *addressImgView;
@property (nonatomic ,strong) UIImageView *timeImgView;
@property (nonatomic ,strong) UIButton *btn;

@end
@implementation CHNoCheckCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype) cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHNoCheckCell";
    CHNoCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CHNoCheckCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        [self setupUI];
    }
    return self;
    
}

-(void)setupUI{
    
    self.photoImgView = [[UIImageView alloc] init];
    self.photoImgView.layer.cornerRadius = 5;
    self.photoImgView.layer.masksToBounds = YES;
    self.photoImgView.image = [UIImage imageNamed:@"img_01"];
    [self.contentView addSubview:self.photoImgView];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"杭州车路湾汽车修理有限公司";
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.timeLabel.textColor =  [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [self.contentView addSubview:self.titleLabel];
    
    
    self.addressLabel = [[UILabel alloc] init];
    self.addressLabel.text = @"杭州萧山区湾曙光村";
    self.addressLabel.textColor =  [UIColor colorWithHexString:@"999999" alpha:1.0f];
    self.addressLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.addressLabel];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.text = @"2017-05-05 14:28";
    self.timeLabel.textColor =  [UIColor colorWithHexString:@"999999" alpha:1.0f];
    [self.contentView addSubview:self.timeLabel];
    
    
    self.addressImgView = [[UIImageView alloc] init];
    self.addressImgView.image = [UIImage imageNamed:@"position"];
    [self.contentView addSubview:self.addressImgView];
    
    
    self.timeImgView = [[UIImageView alloc] init];
    self.timeImgView.image = [UIImage imageNamed:@"time"];
    [self.contentView addSubview:self.timeImgView];
    
    
    self.btn = [[UIButton alloc] init];
    self.btn.userInteractionEnabled = YES;
    [self.btn setTitle:@"去审核" forState:UIControlStateNormal];
    [self.btn setTitleColor:[UIColor colorWithHexString:@"168bce" alpha:1.0f] forState:UIControlStateNormal];
    self.btn.titleLabel.font = [UIFont systemFontOfSize:12];
    self.btn.layer.borderColor = [UIColor colorWithHexString:@"168bce" alpha:1.0f].CGColor;
    self.btn.layer.borderWidth = 1;
    self.btn.layer.cornerRadius = 3;
    self.btn.layer.masksToBounds = YES;
    [self.btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.btn];
}


-(void)setModel:(CHNoCheckModel *)model{
    _model = model;
    
    [self.photoImgView sd_setImageWithURL:[NSURL URLWithString:model.companyphoto] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.titleLabel.text = model.name;
    self.addressLabel.text = model.address;
    self.timeLabel.text = model.submittime;
    
}


-(void)btnClick:(UIButton *)btn{
    
    if (self.block) {
        self.block();
    }
    
}



-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.photoImgView.frame = CGRectMake(10, 15, 130, 90);
    self.titleLabel.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame) +10, 15, UIScreenW - CGRectGetMaxX(self.photoImgView.frame) - 15, 20);
    self.addressImgView.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame)+10, CGRectGetMaxY(self.titleLabel.frame)+6 , 10, 13);
    self.addressLabel.frame = CGRectMake(CGRectGetMaxX(self.addressImgView.frame)+5, CGRectGetMaxY(self.titleLabel.frame)+5, UIScreenW - CGRectGetMaxX(self.addressImgView.frame) - 5, 15);
    self.timeImgView.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame) +10, CGRectGetMaxY(self.addressLabel.frame)+7, 11, 11);
    
    self.timeLabel.frame = CGRectMake(CGRectGetMaxX(self.timeImgView.frame) +5, CGRectGetMaxY(self.addressLabel.frame) +5, UIScreenW - CGRectGetMaxX(self.timeImgView.frame) - 5, 15);
    
    self.btn.frame = CGRectMake(CGRectGetMaxX(self.photoImgView.frame) +10, CGRectGetMaxY(self.timeLabel.frame) +5, 60, 25);
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
